package com.bluegalaxy.sitescore.service.impl;

import com.baomidou.framework.annotations.Log;
import com.bluegalaxy.sitescore.common.enums.RecordStatus;
import com.bluegalaxy.sitescore.entity.User;
import org.springframework.stereotype.Service;

import com.bluegalaxy.sitescore.mapper.TbUserMapper;
import com.bluegalaxy.sitescore.entity.TbUser;
import com.bluegalaxy.sitescore.service.ITbUserService;
import com.bluegalaxy.sitescore.service.support.BaseServiceImpl;

/**
 *
 * TbUser 表数据服务层接口实现类
 *
 */
@Service
public class TbUserServiceImpl extends BaseServiceImpl<TbUserMapper, TbUser> implements ITbUserService {

    @Log("登录")
    @Override
    public TbUser selectByLoginName(String loginName,String password){
        TbUser user = new TbUser();
        user.setUsername(loginName);
        user.setPassword(password);
        user.setStatus(RecordStatus.Effective.getValue());
        return super.selectOne(user);
    }

    @Log("登录")
    @Override
    public TbUser selectByLoginName(String loginName){
        TbUser user = new TbUser();
        user.setUsername(loginName);
        user.setStatus(RecordStatus.Effective.getValue());
        return super.selectOne(user);
    }

    @Log("删除用户")
    @Override
    public void deleteUser(Long userId) {
        TbUser tbUser=super.selectById(userId);
        tbUser.setId(userId.intValue());
        tbUser.setStatus(0);
        super.updateById(tbUser);
    }

    @Log("添加用户")
    @Override
    public boolean insertSelective(TbUser entity) {
        TbUser user = new TbUser();
        user.setUsername(entity.getUsername());
        if(super.selectCount(user)!=0)
            return false;
        else
        return  super.insert(entity);
    }
}